package com.tarena.lbs.business.service.impl;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.dao.repository.BusinessCategoryRepository;
import com.tarena.lbs.business.pojo.po.BusinessCategoryPO;
import com.tarena.lbs.business.pojo.query.BusinessCategoryQuery;
import com.tarena.lbs.business.pojo.vo.BusinessCategoryVO;
import com.tarena.lbs.business.service.BusinessCategoryService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

// 关键：@Service 注解必须存在，且实现 BusinessCategoryService 接口
@Slf4j
@Service
public class BusinessCategoryServiceImpl implements BusinessCategoryService {

    @Resource
    private BusinessCategoryRepository businessCategoryRepository;


    @Override
    public List<BusinessCategoryVO> getAllCategories() {
        log.info("调用仓储层查询所有商家分类");

        List<BusinessCategoryPO> poList = businessCategoryRepository.getAllCategories();
        // 转换PO为VO
        List<BusinessCategoryVO> voList = poList.stream()
                .map(po -> {
                    BusinessCategoryVO vo = new BusinessCategoryVO();
                    BeanUtils.copyProperties(po,vo);
                    return vo;
                })
                .collect(Collectors.toList());

        log.info("商家分类数据转换完成，共{}条", voList.size());
        return voList;
    }


}
